//
//  KLVipSubscriptionCell.m
//  Meboo
//
//  Created by kyo on 2024/1/10.
//

#import "KLVipSubscriptionCell.h"
#import <YYText/YYLabel.h>
#import <YYText/NSAttributedString+YYText.h>
#import "MBWebViewController.h"
@interface KLVipSubscriptionCell()
@property(nonatomic,strong) YYLabel *titleLab;
@end

@implementation KLVipSubscriptionCell
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
//        [self setProtocolHighLight];
    }
    return self;
}

#pragma mark - Public Metohd
- (void)setProtocolHighLight {
    __WeakSelf
    NSString *content = @"Auto-renewal Subscription\n\n(1) 1-month auto-renewal subscription plans are available.\n\n(2) Auto-renewal subscriptions are renewed automatically 24 hours prior to the end of the current subscription period and billed automatically through iTunes.\n\n(3) To cancel auto-renewal subscription, please go to [Settings]->[iTunes & AppStore]->[Apple ID] ->[View Apple ID]->[Subscription] unsubscribe at least 24 hours before the end of the current subscription period. For users pay via Apple App Store, please refer to http://support.apple.com/kb/ht4098";
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:content];
    attributedString.yy_font = MBHelFontSizeScale(14);
    attributedString.yy_color = HEXS(@"666666");
    YYTextHighlight *highlightUserProtocol = [[YYTextHighlight alloc] init];
    highlightUserProtocol.tapAction = ^(UIView *containerView, NSAttributedString *text, NSRange range, CGRect rect) {
        MBWebViewController *webVC = [[MBWebViewController alloc] init];
        [webVC loadWithURL:[NSURL URLWithString:@"http://support.apple.com/kb/ht4098"]];
        webVC.titleStr = @"cancel subscription";
        [weakSelf.currentViewController.navigationController pushViewController:webVC animated:YES];
    };
    NSRange rangeUserProtocol = [content rangeOfString:@"http://support.apple.com/kb/ht4098"];
    [attributedString yy_setColor:[UIColor colorWithRed:16 / 255.0 green:116 / 255.0 blue:226 / 255.0 alpha:1] range:rangeUserProtocol];
    [attributedString yy_setTextHighlight:highlightUserProtocol range:rangeUserProtocol];
    self.titleLab.attributedText = attributedString;
}
#pragma mark - Action

#pragma mark - UI
- (void)setupUI {
    self.contentView.backgroundColor = [UIColor colorWithRed:255 / 255.0 green:255 / 255.0 blue:255 / 255.0 alpha:0.7];
    self.contentView.layer.cornerRadius = MBHeightScale(10);
    
    [self.contentView addSubview:self.titleLab];
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(MBHeightScale(0));
        make.left.mas_equalTo(MBWidthScale(6));
        make.right.mas_equalTo(MBWidthScale(-6));
        make.bottom.mas_equalTo(MBHeightScale(-2));
    }];
}

#pragma mark - Setter && Getter


- (YYLabel *)titleLab {
    if (!_titleLab) {
        _titleLab = [YYLabel new];
        _titleLab.numberOfLines = 0;
        _titleLab.text = @"Membership Notice\n1.  The monthly membership is valid for 30 days.\n2.  Upon purchasing a membership, you will receive the corresponding membership benefits for the current month.\n3.  Renewal or additional purchases will automatically extend the validity period, and the benefits will be available during the corresponding period.\n\nAuto-Renewal Instructions\n1.  Payment: \"Auto-Renewal Monthly Subscription\" is a subscription with automatic renewal.  After confirming the purchase, the payment will be deducted from your Apple iTunes account.\n2.  Renewal: The Apple iTunes account will be charged 24 hours before the subscription expires, and the membership validity period will be automatically extended by 1 month after the payment.\n3.  Canceling the renewal: Please manually disable the auto-renewal feature in the Apple ID account settings at least 24 hours before the subscription expires.";
        _titleLab.font = PDRegularScale(14);
        _titleLab.textColor = HEXS(@"000000");
    }
    return _titleLab;
}
@end
